PROJECTNAME=tlg
CC=g++ # using cpp version
FLAGS=-std=c++20 -pedantic -g
FLAGS+=-Wall -Wextra -Werror=vla -Wno-unused-parameter
FLAGS+=-DTLG_VERSION="0.0.1" # Write as hard code
LINK=-lpam -lxcb
VALGRIND=--show-leak-kinds=all --track-origins=yes --leak-check=full --supressions=../res/valgrind.supp
CMD=./${PROJECTNAME}

OS:=`uname -s`
ifeq (${OS}, Linux)
	FLAGS+=-D_DEFAULT_SOURCE
endif



BINDIR=bin
OBJDIR=obj
SRCDIR=src
THIRDDIR=thirdparty
RESDIR=res
TESTDIR=tests

DATADIR?=${DESTDIR}/etc/tlg
FLAGS+=-DDATADIR=\"${DATADIR}\"# for sure path is like "a b c"?

INCDIR=-I{SRCDIR}
INCDIR+=-I{THIRDDIR}/ctypes
#TODO: include dir to add

.PHONY: build-tlg
build-tlg: ${BINDIR}/${PROJECTNAME}

${OBJDIR}/%.o: %.cpp
	@echo  "Building Obj files, .cpp convert to .o files"
	@mkdir -p ${@D}
	@${CC} ${INCDIR} ${FLAGS} -c -o %@ $<

# TODO: 3rd dir target

# alias as build-tlg
${BINDIR}/${PROJECTNAME}: ${SRC_OBJS}


run-tlg:
	@cd ${BINDIR} && ${CMD}


check-leak: ${BINDIR}/${PROJECTNAME}
	@rm -rf valgrind.log
	@cd ${BINDIR} && valgrind ${VALGRIND} 2> ../valgrind.log ${CMD}
	@less valgrind.log










print-os:
	echo ${OS}

print-defined-dirs:
	echo ${BINDIR}
	echo ${OBJDIR}
	echo ${SRCDIR}
	echo ${RESDIR}
	echo ${TESTDIR}
	echo ${DATADIR}
	echo ${DESTDIR}
	echo ${INCDIR}
	echo ${THIRDDIR}

print-defined-build-stuff:
	echo ${FLAGS}
	echo ${CC}
	echo ${LINK}


print-all-defined-print-target: print-os print-defined-dirs print-defined-build-stuff


clean:
	@echo "rm -rf build file now"
	@rm -rf ${BINDIR} ${OBJDIR} valgrind.log
	@(cd ${THIRDDIR}/termbox_next && ${MAKE} clean)
	# DONE target: clean check-leak run-tlg
	# Helper target: print-<**>
